/**HEADER********************************************************************
*
* Copyright (c) 2008-2011 Freescale Semiconductor;
* All Rights Reserved
*
* Copyright (c) 2004-2010 Embedded Access Inc.;
* All Rights Reserved
*
* Copyright (c) 1989-2008 ARC International;
* All Rights Reserved
*
***************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
*
* $FileName: timer_mpxs30.c$
* $Version : 3.8.1.0$
* $Date    : Oct-5-2011$
*
* Comments:
*
*    This file contains definitions for the Qoriwa PIT timer driver.
*
*END***********************************************************************/


#include "mqx.h"
#include "bsp.h"


static const PSP_INTERRUPT_VECTOR_TABLE _qpit_vectors[] =
{
   MPXS30_INTC_PIT_0_VECTOR,
   MPXS30_INTC_PIT_1_VECTOR,
   MPXS30_INTC_PIT_2_VECTOR,
   MPXS30_INTC_PIT_3_VECTOR
};

static const uint_32 channel_config[] = {
   CORECFG_PIT_0_TIMER_0, CORECFG_PIT_0_TIMER_1,
   CORECFG_PIT_0_TIMER_2, CORECFG_PIT_0_TIMER_3 };


/*FUNCTION*-------------------------------------------------------------
*
* Function Name    : _bsp_qpit_enable_access
* Returned Value   : True if enabled
* Comments         :
*    This function enables the specified device.
*
*END*-----------------------------------------------------------------*/

boolean _bsp_qpit_enable_access(uint_32 channel)
{
    if (channel < ELEMENTS_OF(channel_config)) {
        if (_psp_core_peripheral_enabled(CORECFG_PIT_0)) {
            return _qpbridge_enable_access(MPXS30_PBRIDGE_PIT);
        }
    }
    return FALSE;
}



/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    : _qpit_vector
* Returned Value   : vector #
* Comments         :
*
*
*END*----------------------------------------------------------------------*/

PSP_INTERRUPT_VECTOR_TABLE _bsp_get_qpit_vector
    (
        uint_32 device,
        uint_32 channel
    )
{
    return (PSP_INTERRUPT_VECTOR_TABLE) (device==0) ? _qpit_vectors[channel] : 0;
}


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    : _bsp_get_qpit_base_address
* Returned Value   : none
* Comments         :
*    Get base address of qpit
*
*END*------------------------------------------------------------------------*/


VQPIT_REG_STRUCT_PTR _bsp_get_qpit_base_address(uint_32 device)
{
    if (device == 0) {
        return (VQPIT_REG_STRUCT_PTR) MPXS30_PIT_BASE;
    }
    return NULL;
}
